<?php
namespace Components\Staff;

class Adapter {
  public static function load(array $config) {
    Di::getDI() -> set('config', function() use ($config) {
      if (!isset($config['adapter']) || empty($config['adapter']) || !is_string($config['adapter'])) {
        throw new \Exception('A "adapter" option is required and must be a nonempty string.');
      }
      $config['adapter'] = ucfirst(strtolower($config['adapter']));

      if (!isset($config[$config['adapter']])) {
        throw new \Exception('A "' . $config['adapter'] . '" option is required and must be a nonempty string.');
      }

      return new \Phalcon\Config($config);
    });

    return Di::getDI();
  }
}
